/**
 * Created by zhangzhihao on 2016/12/06 11:00;
 */
var vm = new Vue({
    el: '#main',
    data: {
       	userDatas : {},
		pagination: [],
		queryData:{
			nowPage:1,
			rowNum:10,
			object:{}
		},
		pageNum:null,
		deleteDatas:{
			datas:[]
		},
		optTypes:[]
    },
    created: function () {
        this.queryUser();
        this.queryUserType();
        
        setTimeout(function(){
        	$('#optType').on('change', function() {
                vm.queryData.object.optType = $(this).val();
            });
        	$('#optStatus').on('change', function() {
                vm.queryData.object.optStatus = $(this).val();
            });
        }, 1);
    },
    methods: {
        selectPage:function(page){
            this.queryData.nowPage = page;
            this.queryUser();
        },
        offsetPage:function(offset){
            this.queryData.nowPage = this.queryData.nowPage + offset;
            this.queryUser();
        },
        queryUser:function(reset){
        	if(reset){
				this.queryData.nowPage = 1;
			}
        	App.ajax({
    			type:"POST",
    			url:App.getApiUrl("queryUserURL"),
    			data:this.queryData,
    			success:function(data){
    				vm.userDatas = data;

                    vm.queryData.nowPage = vm.userDatas.nowPage;
                    vm.queryData.allPages = vm.userDatas.allPages;
                    vm.pagination = getPagination(vm.queryData.nowPage,vm.queryData.allPages);
				}
			});
        },
        queryUserType:function(){
        	App.ajax({
    			type:"GET",
    			url:App.getApiUrl("queryUserTypeURL"),
    			success:function(data){
    				vm.optTypes = data;
				}
			});
        },
        addBtn:function(){
        	window.location.href = App.getBaseUrl() + "sys/user/add.html";
		},
        allBtn:function(){
            var checkBoxs = $(".anyCheck");
            var checked = $("#allCheck")[0].checked;
            if(checked){
                for(var i=0;i<checkBoxs.length;i++){
                    checkBoxs[i].checked = true;
                }
            } else {
                for(var i=0;i<checkBoxs.length;i++){
                    checkBoxs[i].checked = false;
                }
            }
        },
        //重置按钮
        resetBtn:function(){
            window.location.reload();
        },
        deleteUsers:function(){
        	vm.deleteDatas.datas = [];
            $("input[name='any']:checked").each(function(){
                vm.deleteDatas.datas.push({optNo:$(this).val()});
            });
            if(vm.deleteDatas.datas.length > 0){
            	parent.showConfirm(
            		"提示信息",
            		"确定要删除所选用户吗？",
            		function(){
            			App.ajax({
                			type:"POST",
                			url:App.getApiUrl("deleteUserURL"),
                			data:vm.deleteDatas,
                			success:function(data){
                				parent.showAlert(data.msg,function(){
                            		window.location.reload();
                            	});
            				}
            			});
            		}
            	);
            }
        },
        gotoPage:function(url,optNo){
            window.location.href = App.getBaseUrl() + url + "?optNo=" + optNo;
        }
    }
});

function rowNumChange(value){
    vm.queryData.rowNum = value;
    vm.queryData.nowPage = 1;
    vm.queryUser();
}